var a = getApp();

Page({
    data: {
        newsList: [],
        page: 1,
        limit: 10,
        hasMore: !0,
        baseUrl: a.globalData.baseUrl,
        userId: wx.getStorageSync("userId")
    },
    onLoad: function(a) {
        var t = this;
        t.setData({
            storeId: a.storeid
        }), t.getInitNewsList(a.storeid);
    },
    getInitNewsList: function(t) {
        var e = this;
        wx.request({
            url: e.data.baseUrl + a.globalData.urlNewCateList,
            data: {
                lng: a.globalData.lng,
                lat: a.globalData.lat,
                storeId: t
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(s) {
                var o = JSON.parse(s.data);
                if (0 != o.code) wx.showToast({
                    title: o.msg,
                    icon: "none",
                    duration: 2e3
                }); else {
                    var n = o.cates[0] ? o.cates[0] : "";
                    e.setData({
                        newCateList: o.cates,
                        cateId: n.id ? n.id : ""
                    }), wx.request({
                        url: e.data.baseUrl + a.globalData.urlNewsList,
                        data: {
                            lng: a.globalData.lng,
                            lat: a.globalData.lat,
                            storeId: t,
                            cateId: e.data.cateId,
                            page: e.data.page,
                            limit: e.data.limit
                        },
                        method: "POST",
                        header: {
                            "content-type": "application/x-www-form-urlencoded"
                        },
                        success: function(a) {
                            var t = JSON.parse(a.data);
                            console.log(t), 0 != t.code && wx.showToast({
                                title: t.msg,
                                icon: "none",
                                duration: 2e3
                            });
                            var s = e.data.page, o = e.data.newsList;
                            t.newsList.length < e.data.limit ? e.setData({
                                newsList: o.concat(t.newsList),
                                hasMore: !1,
                                page: s + 1
                            }) : e.setData({
                                newsList: o.concat(t.newsList),
                                hasMore: !0,
                                page: s + 1
                            });
                        }
                    });
                }
            }
        });
    },
    navNew: function(t) {
        var e = this;
        e.setData({
            cateId: t.currentTarget.dataset.newid,
            page: 1,
            limit: 20,
            newsList: []
        }), wx.request({
            url: e.data.baseUrl + a.globalData.urlNewsList,
            data: {
                lng: a.globalData.lng,
                lat: a.globalData.lat,
                storeId: e.data.storeId,
                cateId: e.data.cateId,
                page: e.data.page,
                limit: e.data.limit
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                var t = JSON.parse(a.data);
                console.log(t), 0 != t.code && wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 2e3
                });
                var s = e.data.page, o = e.data.newsList;
                t.newsList.length < e.data.limit ? e.setData({
                    newsList: o.concat(t.newsList),
                    hasMore: !1,
                    page: s + 1
                }) : e.setData({
                    newsList: o.concat(t.newsList),
                    hasMore: !0,
                    page: s + 1
                });
            }
        });
    },
    onReachBottom: function() {
        var t = this;
        t.data.userId && 0 != t.data.userId.length ? t.getInitNewsList(t.data.storeId) : a.goLogin();
    },
    onShareAppMessage: function() {}
});